package cn.mesmile.auth.service.impl;

import cn.dev33.satoken.stp.StpInterface;
import cn.mesmile.auth.service.UmsAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zb
 * @date 2021/8/19 11:22
 * @Description
 */
@Component
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    private UmsAdminService adminService;

    /**
     * 该账号id具有的权限码集合
     * @param loginId
     * @param loginType 账号类型，多账号体系时以此值区分，比如：login、user、admin
     * @return
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
//        AdminUser adminUser = adminService.getAdminById(Convert.toLong(loginId));
//        return adminUser.getRole().getPermissionList();
        List<String> permissionList = new ArrayList<>();
        if (loginId.equals("user")){
            permissionList.add("brand:add");
        }
        if (loginId.equals("admin")){
            permissionList.add("brand:add");
            permissionList.add("brand:delete");
        }
        return permissionList;
    }

    /**
     * 该账号id具有的角色标识集合
     * @param loginId
     * @param loginType 账号类型，多账号体系时以此值区分，比如：login、user、admin
     * @return
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
//        AdminUser adminUser = adminService.getAdminById(Convert.toLong(loginId));
//        return Collections.singletonList(adminUser.getRole().getName());
        List<String> roleList = new ArrayList<>();
        if (loginId.equals("user")){
            roleList.add("ROLE_USER");
        }
        if (loginId.equals("admin")){
            roleList.add("ROLE_ADMIN");
        }
        return roleList;
    }

}
